package com.cy.pj.sys.service;

import com.cy.pj.common.exception.ServiceException;
import com.cy.pj.sys.dao.SysNoticeDao;
import com.cy.pj.sys.pojo.SysNotice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Slf4j  //@Slf4J 用于为描述的类添加一个日志属性对象。
@Service
public class SysNoticeServiceImpl implements SysNoticeService{

    //private static final Logger log = LoggerFactory.getLogger(SysNoticeServiceImpl.class);

    @Autowired
    private SysNoticeDao sysNoticeDao;

    @Override
    public int saveNotice(SysNotice notice) {
        int rows = sysNoticeDao.insertNotice(notice);
        return rows;
    }

    @Override
    public List<SysNotice> findNotices(SysNotice notice) {
        log.debug("start: {}",System.currentTimeMillis());
        List<SysNotice> list = sysNoticeDao.selectNotice(notice);
        log.debug("end: {}",System.currentTimeMillis());
        return list;
    }

    @Override
    public int deleteById(Long... id) {
        int rows = sysNoticeDao.deleteById(id);
        if (rows==0)
            throw new ServiceException("记录可能已经不存在");
        return rows;
    }

    @Override
    public SysNotice findById(Long id) {
        SysNotice notice = sysNoticeDao.selectById(id);
        if (notice==null)
            throw new ServiceException("可能记录已经不存在");
        return notice;
    }

    @Override
    public int updateNotice(SysNotice notice) {
        int rows = sysNoticeDao.updateNotice(notice);
        return rows;
    }
}
